/* eslint-disable */
/**
 * @name 返回一个在所有给定的promise都已经fulfilled或rejected后的promise，并带有一个对象数组，每个对象表示对应的promise结果
 * @param {promise} promises
 * @returns  promise
 */
const race = function race(promises) {
  if (!Array.isArray(promises)) throw new Error('Argument must be an array.');
  let _resolve, _reject;
  const retPromise = new Promise((resolve, reject) => {
    _resolve = resolve;
    _reject = reject;
  });
  for (const promise of promises) {
    Promise.resolve(promise).then(_resolve, _reject);
  }
  return retPromise;
};

export default race;
